#include "GeneratorExp.h"
#include "IVisitor.h"

GeneratorExp::GeneratorExp(const exprTypePtr& elt, const ComprehensionTypeList& generators, int nodeId):
    exprType(nodeId),
    _elt(elt),
    _generators(generators)
{
}
    
GeneratorExp::~GeneratorExp()
{
    _generators.clear();
}
    
Ast::AstTypes GeneratorExp::type() const
{
    return Ast::GeneratorExp;
}
    

exprTypePtr GeneratorExp::elt()
{
    return _elt;
}

void GeneratorExp::setElt(const exprTypePtr& elt)
{
    _elt = elt;
}

ComprehensionTypeList GeneratorExp::generators()
{
    return _generators;
}

void GeneratorExp::setGenerators(const ComprehensionTypeList& generators)
{
    _generators = generators;
}

    
QString GeneratorExp::toString() const
{
    return QString("GeneratorExp[elt=%1, generators=%2]").
                arg(_elt ? _elt->toString():"").
                arg(_generators.toString());
}
    
void GeneratorExp::accept(IVisitor* visitor, const SimpleNodePtr& node)
{
    visitor->visitGeneratorExp(node.dynamicCast<GeneratorExp>());
}
    
void GeneratorExp::traverse(IVisitor* visitor)
{
    if (_elt != NULL)
        _elt->accept(visitor, _elt);
    _generators.traverse(visitor);
}